<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib prefix ="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>编辑学生</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/layui/css/layui.css"
	media="all">
</head>
<body>
	<form class="layui-form layui-form-pane" action="">
		<div class="layui-form-item">
			<label class="layui-form-label">编号</label>
			<div class="layui-input-inline">
				<input type="text" name="id" lay-verify="required"
					   placeholder="请输入" autocomplete="off" class="layui-input" value="${student.id}" disabled>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">学号</label>
			<div class="layui-input-inline">
				<input type="text" name="sn" lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input" value="${student.sn}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-inline">
				<input type="text" name="name" lay-verify="required"
					   placeholder="请输入" autocomplete="off" class="layui-input" value="${student.name}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-inline">
<%--				<input type="text" name="sex" lay-verify="required"--%>
<%--					placeholder="请输入" autocomplete="off" class="layui-input" value="${student.sex}">--%>
	<select name="sex" lay-filter="sex">
		<option value="男" ${student.sex=='男'?'selected':''}>男</option>
		<option value="女" ${student.sex=='女'?'selected':''}>女</option>
		<option value="未知" ${student.sex=='未知'?'selected':''}>未知</option>
	</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">身高</label>
			<div class="layui-input-inline">
				<input type="text" name="height" lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input" value="${student.height}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">班级</label>
			<div class="layui-input-inline">
				<select name="cid" lay-filter="cid" >
					<c:forEach items="${clazzes}" var="clazz">
						<option value="${clazz.cid}" ${clazz.cid==student.cid?"selected":""}>${clazz.cname}</option>
					</c:forEach>
				</select>
			</div>
		</div>
<%--		<div class="layui-form-item">--%>
<%--			<label class="layui-form-label">用户图片</label>--%>
<%--			<div class="layui-input-inline">--%>
<%--				<input type="text" name="userImg" required id="userPath" lay-verify="required"--%>
<%--					   lay-reqtext="视频封面是必填选项,岂能为空?" placeholder="请输入" autocomplete="off" class="layui-input layui-disabled" value="${student.userImg}">--%>
<%--				<div class="layui-upload">--%>
<%--					<button type="button" class="layui-btn" id="chooseImg">上传图片</button>--%>
<%--					<div class="layui-upload-list">--%>
<%--						<img class="layui-upload-img"--%>
<%--							 src="${pageContext.request.contextPath}/upload/${student.userImg}"--%>
<%--							 id="demo1" style="width: 80px; height: 80px">--%>
<%--						<p id="demoText"></p>--%>
<%--					</div>--%>
<%--				</div>--%>
<%--			</div>--%>
<%--		</div>--%>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" lay-submit=""
					lay-filter="demo1">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</body>
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script>
layui.use([ 'upload', 'element', 'layer' ],function() {
		var $ = layui.jquery,
		upload = layui.upload,
		element = layui.element,
		layer = layui.layer,
		form = layui.form;

	//常规使用 - 普通图片上传
	var uploadInst = upload.render({
		elem : '#chooseImg',
		url : 'UploadStudentServlet', //自己的上传Servlet
		accept:"images",//指定上传文件的类型
		auto:true,//选完文件自动上传
		before:function(obj) {
			//预读本地文件示例，不支持ie8
			obj.preview(function(index, file, result) {
				$('#demo1').attr('src', result); //图片链接（base64）
			});
		},
		done: function(res){
			$("#userPath").val(res.data);
		}
	});
		//提交表单
		form.on('submit(demo1)', function(data){
		 //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
		  $.ajax({
			  url:"AdmineditStudentServlet2",
			  data:data.field,
			  type:"post",
		  })
		  window.location.reload()//让父窗口重新加载
		  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
})
</script>
</html>
